﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Aliyeye.Car.Net.UI.PopupDialog;
using Aliyeye.Car.Net.UI.Common;

namespace Aliyeye.Car.Net.UI.SystemHelp
{
    public partial class MakePass : BaseForm
    {
        AccountsUsersSvc.SoapHeaderClass sopaHeader = new AccountsUsersSvc.SoapHeaderClass();

        public MakePass()
        {
            InitializeComponent();
        }

        private void menuBlueButton1_Click(object sender, EventArgs e)
        {
            if (txtpass.Text.Trim() != txtpass1.Text.Trim())
            {
                PageCommon.Alert("新密码输入不一致，请重新输入！");
                return;
            }

            overlay.FadeIn();Cursor.Current = Cursors.WaitCursor;
            AccountsUsersSvc.Accounts_Users model = new AccountsUsersSvc.Accounts_Users();
            model.UserID = Login.LogUserId;
            model.Password = Utility.JhEncrypt.EncryptPassword(txtoldpass.Text);
            model.NewPassword = Utility.JhEncrypt.EncryptPassword(txtpass.Text);

            ServiceManipulator.SafeAsyncExecution<AccountsUsersSvc.Accounts_UsersServiceSoapClient>(
                proxy => proxy.UpdatePass(sopaHeader, model),
                result =>
                {
                    if (result.Error == null)
                    {
                        if (Convert.ToBoolean(result.Result))
                        {
                            PageCommon.Notify("密码修改成功！");
                        }
                        else
                        {
                            PageCommon.Alert("密码修改失败！");
                        }
                        overlay.FadeOut();Cursor.Current = Cursors.Default;
                    }
                    else
                    {
                        PageCommon.Error(result.Error.Message); overlay.FadeOut();Cursor.Current = Cursors.Default;
                    }
                },
                this
            );
        }

        private void MakePass_Load(object sender, EventArgs e)
        {

        }
    }
}
